package com.zhiyou100.blog.aciton.title;

import com.zhiyou100.blog.entity.Title;
import com.zhiyou100.blog.service.TitleService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author shkstart
 * @create 2021-10-23 11:44
 * 展示 话题内容 和留言
 */
@WebServlet("/title/showMessage")
public class TitleShowMessageServlet extends HttpServlet {
    private TitleService service = new TitleService();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String tid = request.getParameter("tid");
        if (tid == null) {
            return;
        }
        int id = Integer.parseInt(tid);
        //获取 话题的详细内容 包括留言 包括留言的赞虚
        Title title = service.getOneTitleWithMessage(id);
        System.out.println("查询到的话题详情  title = " + title);
        //if (title != null) {
        request.setAttribute("title", title);
        //}
        /**/


        request.getRequestDispatcher("/index.jsp?pageName=/view/message_detail.jsp").forward(request, response);
    }
}
